<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>0802_回调形式refs</title>
</head>

<body>
  <div id="test1"></div>
  <!-- react核心库 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <!-- 用于支持react操作DOM -->
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <!-- 用于将jsx转为js -->
  <script type="text/javascript" src="../js/babel.min.js"></script>

  <script type="text/babel">

    // 1.创建组件
    class Person extends React.Component {
      // 对标签属性类型、必要性做限制
     
      render() {
        return (
          <div>
            <input ref={c => this.input1 = c} type="text" placeholder="点击按钮提示数据"/>
            <button onClick={this.showData}>点击显示数据</button><br/>
            <input ref={c => this.input2 = c} type="text" placeholder="失去焦点提示数据" onBlur={this.showData1}/>
          </div>
        )
      }
      // 点击提示数据
      showData = () => {
        let {input1} = this
        alert(input1.value)
      }

      // 失去焦点提示数据
      showData1 = () => {
        let {input2} = this
        alert(input2.value)
      }
    }

    // 2.渲染虚拟DOM到页面
    ReactDOM.render(<Person/>, document.getElementById('test1'))
    
  </script>
</body>

</html>